


*************************
*** ==== FIGURE 1 === ***
*************************

use "~\trust_merged", clear

local dv "doctor_trust01 adherence01 med_conf01"
scalar row = 1
matrix A = J(100,10,.)


forvalues i = 0/1 {
	forvalues x = 1/3{
	local outcome `: word `x' of `dv''
	levelsof year if `outcome'!=., local(levels)
		foreach l of local levels{
			
			if `x'==2 {
			sum `outcome' if demrep==`i' & year==`l' & age>=50 & age!=. [aweight=weight]
			matrix A [row,1] = r(mean)
			matrix A [row,2] = `i'
			matrix A [row,3] = `l'
			matrix A [row,4] = `x'
			matrix A [row,5] = r(sd)/sqrt(r(N))
			
			}
			
			else {
			sum `outcome' if demrep==`i' & year==`l' [aweight=weight]
			matrix A [row,1] = r(mean)
			matrix A [row,2] = `i'
			matrix A [row,3] = `l'
			matrix A [row,4] = `x'
			matrix A [row,5] = r(sd)/sqrt(r(N))

			
			}
			
			scalar row = row + 1
	
}
}
}

preserve
svmat A
keep A1-A5
g outcome = "doctor_trust01" if A4==1
replace outcome = "adherence01" if A4==2
replace outcome = "med_conf01" if A4==3
rename A1 mean
rename A2 demrep
rename A3 year
rename A5 se

save "~\cross_section_mean", replace
restore




*************************
*** ==== FIGURE 2 === ***
*************************

* DATA ARE FROM THE GSS CUMULATIVE FILE (1972-2022), FREE TO DOWNLOAD, HERE; https://gss.norc.org/us/en/gss/get-the-data.html

use "~\gss.dta", clear


recode partyid 0/2=0 4/6=1 else=., g(demrep) 

local vars "conmedic conlabor contv coneduc conclerg conbus consci conarmy conpress confed conjudge conlegis"
scalar var_count = `:word count `vars''
di var_count


svyset [pweight=wtssps], strat(vstrat) psu(vpsu) singleunit(scaled)


matrix A = J(800,10,.)
g row = 1

forvalues i = 1/12 {

	local outcome `: word `i' of `vars''
	
	replace `outcome' = 4 - `outcome'
	
	levelsof year if inrange(`outcome',1,3) & inrange(year,1988,2022), local(levels)
		foreach l of local levels{
			
			svy: reg `outcome' demrep if year==`l'
			
			matrix A[row,1] = _b[demrep]
			matrix A[row,2] = _se[demrep]
			matrix A[row,3] = _b[demrep] + invt(e(df_r), .975)*_se[demrep]
			matrix A[row,4] = _b[demrep] - invt(e(df_r), .975)*_se[demrep]
			matrix A[row,5] = `l'
			matrix A[row,6] = `i'
			matrix A[row,7] = 99
			
			replace row = row + 1
			
			* For D & R 
			
			forvalues d = 0/1 {
				
			svy: mean `outcome'  if year==`l' & demrep==`d'
			
			matrix A[row,1] = r(table)[1,1]
			matrix A[row,2] = r(table)[2,1]
			matrix A[row,3] = r(table)[6,1]
			matrix A[row,4] = r(table)[5,1]
			matrix A[row,5] = `l'
			matrix A[row,6] = `i'
			matrix A[row,7] = `d'
			
			replace row = row + 1
	
}
}
}


svmat A
keep A*
rename (A1-A7) (coef se ub lb year var party)
g outcome=""


forvalues i = 1/12 {

	local outcome `: word `i' of `vars''
	replace outcome = "`outcome'" if var==`i'
	
}

drop A*
drop if coef==.
save "~\gss_institutions", replace 


*************************
*** ==== FIGURE 3 === ***
*************************

use "~\prime_bjps", clear


rename adherence_slider_1 adherence
rename personaltrust_slider_1 personaltrust
rename general_confidence_1 confidence


matrix A = J(100,10,.)
matrix B = J(100,10,.)
scalar row = 1
scalar var = 1

foreach x in adherence personaltrust confidence {
	forvalues i = 0/1 {
	
	reg d_`x' `x' treat if votetrump == `i'
	eststo vote`i'
	
	matrix A[row,1] =  _b[treat]
	matrix A[row,2] = _se[treat]
	matrix A[row,3] = e(N)
	matrix A[row,4] = `i'
	matrix A[row,5] = var
	matrix A[row,6] = e(rank)
	
	scalar row = row + 1
	
}

suest vote1 vote0
lincom [vote0_mean]treat  - [vote1_mean]treat
matrix B[row,1] = r(estimate)
matrix B[row,2] = r(se)
matrix B[row,3] = e(N)
matrix B[row,4] = 99
matrix B[row,5] = var
matrix B[row,6] = e(rank)


scalar var = var + 1

}

foreach x in A B {
preserve
svmat `x'
keep `x'1-`x'10
rename `x'1 coef
rename `x'2 se
rename `x'3 obs
rename `x'6 rank
g df = obs - rank
g ub = coef + invt(df,.975)*se
g lb = coef - invt(df,.975)*se
rename `x'4 votetrump
g var = "adherence" if `x'5 == 1
replace var = "personaltrust" if `x'5==2
replace var = "confidence" if `x'5 == 3
drop `x'*
keep if coef!=.

save "~\experiment_results_`x'", replace
restore
}


use "~\experiment_results_A", clear
append using "~\experiment_results_B"
save "~\experiment_results", replace



*************************
*** ==== FIGURE 4 === ***
*************************

use "~\conjoint_bjps", clear

* Conjoint by different partisan measures *
recode trump_ft 0=. 1/100=1 -100/-1=0
g femalex = 1 if malex==0
g all = 1

* For all respondents *
matrix A = J(300,10,.)
scalar row = 1
local iv hispanic black medstar histar dem far ivy male 
local subset all blackx hispanicx femalex

scalar predictor = 1

foreach y in libcon repdem trump_ft votetrump {
forvalues g = 1/4{
local group `: word `g' of `subset''
forvalues i = 0/1 {
	
reg choose hispanic black medstar histar dem far ivy male if `y'==`i' & `group'==1, cluster(responseid)

forvalues x = 1/8 {
local outcome `: word `x' of `iv''

matrix A[row,1] = _b[`outcome']
matrix A[row,2] = _se[`outcome']
matrix A[row,3] = _b[`outcome'] + invt(e(df_r), .975)*_se[`outcome']
matrix A[row,4] = _b[`outcome'] - invt(e(df_r), .975)*_se[`outcome']
matrix A[row,5] = `i'
matrix A[row,6] = `x'
matrix A[row,7] = `g'
matrix A[row,8] = predictor

scalar row = row + 1


}
}
}

scalar predictor = predictor + 1

}

svmat A
keep A*

g measure = ""
local iv hispanic black medstar histar dem far ivy male 

forvalues x = 1/8 {
local outcome `: word `x' of `iv''
replace measure = "`outcome'" if A6 == `x'

}

g subset = ""
forvalues x = 1/4 {
local group `: word `x' of `subset''
replace subset = "`group'" if A7 == `x'

}

rename (A1-A8) (coef se ub lb votetrump index group predictor)
drop A*
drop if coef==.

g pref = "votetrump" if predictor==4
replace pref = "libcon" if predictor == 1
replace pref = "repdem" if predictor == 2
replace pref = "trump_ft" if predictor == 3

save "~\conjoint_results_all", replace


****************************
*** ==== TABLE 2 & 3 === ***
****************************

use "~\zocdoc_bjps", clear

forvalues i = 1/7 {
	
	reg seek treat01 if ideology==`i'
	
}

forvalues i = 1/7 {
	
	reg email treat01 if ideology==`i'
	
}






